package com.crm.jdy.service.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crm.jdy.common.dto.ClientInvoiceInfoDto;
import com.crm.jdy.common.mapper.TeamInfoMapper;
import com.crm.jdy.common.pojo.ClientChargeInfo;
import com.crm.jdy.common.pojo.ClientInvoiceInfo;
import com.crm.jdy.common.mapper.ClientInvoiceInfoMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**   
 * @Description:(发票信息服务实现)
 *
 * @version: V1.0
 * @author: kong
 * 
 */
@Service(version = "${service.version}")
@Component
public class ClientInvoiceInfoServiceImpl  extends ServiceImpl<ClientInvoiceInfoMapper,ClientInvoiceInfo> implements ClientInvoiceInfoService  {

    @Autowired
    ClientInvoiceInfoMapper clientInvoiceInfoMapper;

    @Override
    public PageInfo<ClientInvoiceInfo> seleteClientInvoiceInfo(ClientInvoiceInfoDto clientInvoiceInfo) {
         PageHelper.startPage( clientInvoiceInfo.getCurrentPage(),clientInvoiceInfo.getPageSize());
         List<ClientInvoiceInfo> bookList = clientInvoiceInfoMapper.seleteClientInvoiceInfo(clientInvoiceInfo);
         PageInfo<ClientInvoiceInfo> pageInfo = new PageInfo<ClientInvoiceInfo>(bookList);
         return pageInfo;
    }

    @Override
    public boolean updateClientInvoiceInfo(ClientInvoiceInfo clientInvoiceInfo) {
        return clientInvoiceInfoMapper.updateById(clientInvoiceInfo) > 0;
    }

    @Override
    public boolean addClientInvoiceInfo(ClientInvoiceInfo clientInvoiceInfo) {
//      LambdaQueryWrapper<ClientChargeInfo> lambda = new QueryWrapper<ClientChargeInfo>().lambda()
//            .eq(ClientChargeInfo::getChargePhone, clientInvoiceInfo.getInvoiceId());
//        ClientChargeInfo clientInfo = clientInvoiceInfoMapper.selectOne(lambda);
//        if( clientInfo !=null && ObjectUtils.isEmpty(clientInfo)){
//            return false;
//        }else{
            return clientInvoiceInfoMapper.insert(clientInvoiceInfo) > 0;
//        }
    }

    @Override
    public boolean removeClientInvoiceInfo(String aplanId) {
        return clientInvoiceInfoMapper.deleteById(aplanId) > 0;
    }

}